<%@ page pageEncoding="UTF-8"%>
<%@ include file="../common/head.jsp"%>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<%@ include file="./msg/meta.jsp"%>
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-row">
			<form action="${ctx}/sys/update${actionclass}.do" method="post" class="layui-form" style="margin-top: 10px"
				id="dataform">
				<input type="hidden" value="${modifybean.id}" name="id" />
				<div class="layui-form-item">
					<label class="layui-form-label">科目</label>
					<div class="layui-input-block">
						<select name="coursesel" id="Question_coursesel" lay-filter="Question_coursesel">
							<option value="科目一">科目一</option>
							<option value="科目四">科目四</option>
						</select>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">车型</label>
					<div class="layui-input-block">
						<select name="cxsel" id="Question_cxsel">
							<option value="所有">所有</option>
							<option value="小车">小车</option>
							<option value="货车">货车</option>
							<option value="客车">客车</option>
						</select>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">分类专项</label>
					<div class="layui-input-block" id="Question_questionItem1" <c:if test="${modifybean.coursesel=='科目四' }">style="display: none"</c:if> >
						<select name="questionItemId1" id="Question_questionItem" lay-verify="required" lay-reqtext="请输入题目">
							<c:forEach items="${list1}" var="item">
								<option value="${item.id }" <c:if test="${modifybean.questionItemId==item.id }">selected="selected" </c:if> >${item.qitem }</option>
							</c:forEach>
						</select>
					</div>
					<div class="layui-input-block" id="Question_questionItem4" <c:if test="${modifybean.coursesel=='科目一' }">style="display: none"</c:if>>
						<select name="questionItemId4" id="Question_questionItem" lay-verify="required" lay-reqtext="请输入题目">
							<c:forEach items="${list4}" var="item">
								<option value="${item.id }" <c:if test="${modifybean.questionItemId==item.id }">selected="selected" </c:if>>${item.qitem }</option>
							</c:forEach>
						</select>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">题型</label>
					<div class="layui-input-block">
						<select name="quesType" id="Question_quesType">
							<option value="单选题">单选题</option>
							<option value="判断题">判断题</option>
							<option value="多选题">多选题</option>
						</select>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">分值</label>
					<div class="layui-input-block">
						<input type="text" name="score" id="Question_score" value="${modifybean.score}" lay-verify="required|number" lay-reqtext="请输入分值"
							placeholder="" autocomplete="off" class="layui-input" readonly="readonly">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">图片</label>
					<div class="layui-input-block">
						<div class="layui-upload-drag" id="file_imgFile">
							<i class="layui-icon"></i>
							<p>点击上传，或将文件拖拽到此处</p>
							<div class="" id="view_imgFile">
								<img src="${ctx}/resource/${modifybean.imgFile}" alt="请上传文件" style="max-width: 196px"
									onerror="javascript:this.src='${ctx}/resource/no-small.jpg'">
							</div>
							<input type="text" value="${modifybean.imgFile}" name="imgFile" id="text_imgFile" readonly="readonly"
								style="width: 100%; border: none;" />
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">题目</label>
					<div class="layui-input-block">
						<textarea rows="5" cols="100" name="title" id="Question_title" class="layui-textarea" lay-verify="required"
							lay-reqtext="请输入题目">${modifybean.title }</textarea>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">答案</label>
					<div class="layui-input-block">
						<input type="text" name="answer" id="Question_answer" value="${modifybean.answer}" lay-verify="required"
							lay-reqtext="请输入答案" placeholder="判断题答案 T : 正确; F : 错误" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">选项A</label>
					<div class="layui-input-block">
						<input type="text" name="option1" id="Question_option1" value="${modifybean.option1}" lay-verify=""
							lay-reqtext="请输入选项A" placeholder="" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">选项B</label>
					<div class="layui-input-block">
						<input type="text" name="option2" id="Question_option2" value="${modifybean.option2}" lay-verify=""
							lay-reqtext="请输入选项B" placeholder="" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">选项C</label>
					<div class="layui-input-block">
						<input type="text" name="option3" id="Question_option3" value="${modifybean.option3}" lay-verify=""
							lay-reqtext="请输入选项C" placeholder="" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">选项D</label>
					<div class="layui-input-block">
						<input type="text" name="option4" id="Question_option4" value="${modifybean.option4}" lay-verify=""
							lay-reqtext="请输入选项D" placeholder="" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">解析</label>
					<div class="layui-input-block">
						<input type="text" name="jiexi" id="Question_jiexi" value="${modifybean.jiexi}" lay-verify="" lay-reqtext="请输入解析"
							placeholder="" autocomplete="off" class="layui-input">
					</div>
				</div>


				<div class="layui-form-item">
					<div class="layui-input-block">
						<button type="submit" class="layui-btn" lay-submit="" lay-filter="sysgo">保存</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
<script>
	$("#Question_coursesel").val("${modifybean.coursesel}");
	$("#Question_cxsel").val("${modifybean.cxsel}");
	$("#Question_quesType").val("${modifybean.quesType}");
	$("#Question_questionItem").val("${modifybean.questionItemId}");

	layui.use([ 'laydate', 'form' ], function() {
		var laydate = layui.laydate;
		var form = layui.form;
		form.verify({
		});
		form.on('select(Question_coursesel)', function(data) {
			var id = data.value;
			$("#Question_questionItem1").hide();
			$("#Question_questionItem4").hide();
			if (id == '科目一') {
				$("#Question_score").val("1");
				$("#Question_questionItem1").show();
			} else {
				$("#Question_score").val("2");
				$("#Question_questionItem4").show();
			}
		});
		form.on('submit(sysgo)', function(data) {
			console.log(data.form.action);
			$.ajax({
				type : 'POST',
				url : data.form.action,
				dataType : 'json',
				data : data.field,
				success : function(data) {
					if (data.statusCode == 200) {
						layer.msg(data.message, {
							icon : 1,
							time : 1000
						}, function() {
							var index = parent.layer.getFrameIndex(window.name);
							parent.location.replace(parent.location.href)
							parent.layer.close(index);

						});
					} else {
						layer.msg(data.message, {
							icon : 2,
						});
					}
				},
				error : function(data) {
					console.log(data);
				},
			});
			return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});
		lay('.date').each(function() {
			laydate.render({
				elem : this,
				type : "date", //year,month,date,time,datetime
				range : false, //范围
				format : "yyyy-MM-dd",
			//value : "",//默认值
			//min/max - 最小/大范围内的日期时间值,正负值
			});
		});
	});
	$(function() {
		layui.use('upload', function() {
			var $ = layui.jquery,
				upload = layui.upload;
			//普通图片上传
			upload.render({
				elem : '#file_imgFile',
				url : '${ctx}/com/fileUpload.do', //改成您自己的上传接口
				accept : "file", //images（图片）、file（所有文件）、video（视频）、audio（音频）
				done : function(res) {
					layer.msg('上传成功');
					if (this.accept == 'images') {
						layui.$('#view_imgFile').removeClass('layui-hide').find('img').attr('src', '${ctx}/resource/' + res.filename);
					}
					$("#text_imgFile").val(res.filename);
				//console.log($(this)[0].accept)
				}
			});


		});
	});
</script>
</html>
<%@ include file="../common/clear.jsp"%>
